﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace _2014112107
{
    public partial class UserDelete : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSelect_Click(object sender, EventArgs e)
        {
            string strSql = "SELECT   日期, 项目1, 支出额, 项目2,收入额, 备注  FROM      project WHERE   (日期 = @Date)";
            SqlParameter[] pms = new SqlParameter[1];
            pms[0] = new SqlParameter("@Date", this.txtDate.Text);
            SqlDataReader dr = SqlHelper.ExecuteReader(strSql, pms);
            if (dr.Read())
            {
                this.txtProject1.Text = dr["项目1"].ToString();
                this.txtNum1.Text = dr["支出额"].ToString();
                this.txtProject2.Text = dr["项目2"].ToString();
                this.txtMemo.Text = dr["备注"].ToString();
                this.txtNum2.Text = dr["收入额"].ToString();
            }
            dr.Close();
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            string strCn = "server=pc.hstc.cn;database=dhd2014112107;uid=2014112107;pwd=19951106";
            SqlConnection cn = new SqlConnection(strCn);
            try
            {
                cn.Open();
                string strDate = this.txtDate.Text;
                //忽略检测规范
                
                string strSql = "DELETE FROM project    WHERE   (日期 = N'"+strDate+"')";
              
                SqlCommand cmd = new SqlCommand(strSql, cn);
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {

                }
                //this.GridView1.DataSource = dr;
                //this.GridView1.DataBind();
                Response.Write("<script>alert('删除记录成功!')</script>");
                dr.Close();
            }
            catch (Exception ex)
            {
                this.lblInfo.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }
    }
}